package sbtest.sbtest;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.ym.demo.dao.impl.PersonDaoImpl;
import org.ym.demo.dao.impl.PersonJdbcDaoImpl;
import org.ym.demo.dao.model.Person;
import org.ym.demo.dao.model.UserInfo;
import org.ym.demo.service.impl.EventServiceImpl;
import org.ym.demo.service.impl.UserServiceImpl;

/**
 * Hello world!
 *
 */
public class App {

	public static void main(String[] args) throws SQLException {
		App app = new App();
		app.readEvent();
		Logger log = LoggerFactory.getLogger(App.class);
		log.info("asdfasdf");
		Log log2 = LogFactory.getLog(App.class);
		log2.info("kdkkdkdkdkkd");
//		app.saveUserTest();
//		app.springjdbc();
//		app.savePerson();
	}

	public void saveUserTest() throws SQLException {
		ApplicationContext context = new ClassPathXmlApplicationContext("/spring-hibernate.xml");
		UserServiceImpl service = (UserServiceImpl) context.getBean("userService");

		UserInfo user = new UserInfo();
		user.setName("bbbk");
		user.setTitle("CSDN BLOG");
		service.addUserInfo(user);
	}

	public void springjdbc() {
		ApplicationContext context = new ClassPathXmlApplicationContext("/spring-hibernate.xml");
		PersonJdbcDaoImpl dao = (PersonJdbcDaoImpl) context.getBean("personJdbcDaoImpl");
		
		List list = dao.getPersons();
		
		System.out.println(list);
	}
	
	public void savePerson(){
		ApplicationContext context = new ClassPathXmlApplicationContext("/spring-hibernate.xml");
		PersonDaoImpl dao = (PersonDaoImpl) context.getBean("personDaoImpl");
		
		Person person = new Person();
		person.setAge(111);
		person.setFirstname("hao");
		person.setLastname("哈哈");
		dao.save(person);
	}
	
	public void readEvent(){
		ApplicationContext context = new ClassPathXmlApplicationContext("/spring-hibernate.xml");
		EventServiceImpl service = (EventServiceImpl) context.getBean("eventServiceImpl");
//		service.getFirstCacheTest();
//		service.add();
		service.getSecondCacheTest();
//		service.get();
		
//		service.updatethree();
	}
}
